<template>
    <div>
        <ul class="menu_top_list ">

            <li @click="add()">
                <span class="iconfont icon-fanhui"></span>

            </li>
            <li>{{ rbq && rbq.title }}</li>
            <li>
                <div class="fav-btn" id="fav" v-show="!this.bbq.guan" @click="Sign()"></div>

                <div class="fav-btn faved-btn" id="faved" v-show="this.bbq.guan" @click="sin()"></div>

            </li>

        </ul>
        <!-- 中间大图 -->
        <div class="collect-detail">
            <img :src="rbq && rbq.img">
            <p>{{ rbq && rbq.pp }}</p>
            <div class="read-info cf">
                <span>{{ rbq && rbq.qq }}浏览</span>
                <em>2022/10/27更新</em>
            </div>
        </div>
        <!-- 游戏数据 -->
        <van-list v-model="loading" :finished="finished" finished-text="没有更多游戏了" @load="onLoad">
            <div class="md-list">
                <div id="list_box">

                    <ul>
                        <van-cell class="list-div" v-for=" (k, index) in this.con " :key="'i-fo-' + index">
                            <li>
                                <router-link :to="'./GameDetails?id=' + k.id">


                                    <img :src="k.pic"><em>{{ k.title }}</em>

                                    <p>{{ k.html5introduce }}</p><span>{{ k.category }} | 人气:{{ k.wapclicks
                                    }}</span><i class="icon-"></i>
                                </router-link>
                                <router-link :to="'/start?id=' + k.id" tag="a" class="btn">开始玩</router-link>

                            </li>
                        </van-cell>
                    </ul>


                </div>
            </div>




        </van-list>
    </div>
</template>
<script>
import { allColl } from '@/api/home';
// import { Toast } from 'vant';
// import { Dialog } from 'vant';

export default {
    data() {
        return {
            con: null,
            obj: [],
            list: [],
            rbq: null,
            bbc: null,
            loading: false,
            finished: false,
            count: 1,
            scrollTop: "",//距离顶部的距离
            scrollHeight: "",//总共的高
            offsetHeight: "",//当前页面的高，
            guan: false,
            bbq:null


        }
    },
    methods: {
        sin(index) {

            if (this.bbq == undefined) {

                this.bbq = { guan: false },

                    // this.bbq.unshift( 1)
                    console.log("!1bbq=>", this.bbq);
            }

            this.bbq.guan = this.rbq.guan = false
            console.log("!rbq", this.rbq);
            console.log("!bbqq", this.bbq);

            // this.$store.commit("collectdel")
            this.$store.commit("likeFundel", index)

        },
        Sign() {
            if (this.bbq == undefined) {

                this.bbq = { guan: true },

                    // this.bbq.unshift( 1)
                    console.log("1bbq=>", this.bbq);
            }
            this.bbq.guan = this.rbq.guan = true
            console.log("rbq", this.rbq);
            console.log("bbqq", this.bbq);

            this.$store.commit("likeFun", this.rbq);



        },

        // 返回go(-1)
        add() {
            this.$router.go(-1)

        },
        allCollFun() {
            // 引入ajox
            allColl({ id: this.$route.query.id }).then(data => {

                let arr = data
                let ac = this.$route.query.id;
                // 获得下标
                let index = arr.findIndex(item => item.id == this.$route.query.id);
                this.rbq = arr[index]





                // this.obj = arr.splice(index, 1);//删除数组

                console.log("rbq", this.rbq);
                // console.log("arr", arr);
                console.log("ac", ac);
                this.list = this.rbq.data

            })
        },
        onLoad() {
            // 异步更新数据
            // setTimeout 仅做示例，真实场景中一般为 ajax 请求
            //当前高度
            this.scrollTop =
                window.pageYOffset ||
                document.documentElement.scrollTop ||
                document.body.scrollTop;
            //总高度
            this.scrollHeight = document.body.scrollHeight;
            //当前屏幕高度
            this.offsetHeight = document.body.offsetHeight;

            if (this.scrollTop + this.offsetHeight + 500 >= this.scrollHeight) {
                setTimeout(() => {
                    for (let i = 0; i < 5; i++) {
                        this.con = this.list.slice(0, this.count++)
                        // console.log("con=", this.con);
                    }


                    // 加载状态结束
                    this.loading = false;

                    // 数据全部加载完成
                    if (this.con.length >= this.list.length) {
                        this.finished = true;
                    }
                }, 1000);
            }
        }


    },
    created() {
        // 获取id
        if ("id" in this.$route.query) {
            this.allCollFun()

        }
        this.edg = this.$store.state.like
        let index1 = this.edg.findIndex(item => item.id == this.$route.query.id);
        this.bbq = this.edg[index1];
        console.log("bbq", this.bbq);
        if (this.bbq == undefined) {

            this.bbq = { guan: false },

                // this.bbq.unshift( 1)
                console.log("1bbq", this.bbq);
        }
    }

}
</script>
<style lang="scss" scoped>
.fav-btn {
    background: url("https://h.4399.com/images/2022/icon.png") no-repeat;
    background-size: 50px 1400px;
    background-position: 10px -163px;
    right: 0;
    top: 5px;
    height: 48px;
    width: 38px;

}

.md-list li span {
    height: 18px;
    line-height: 18px;
    color: #959595;
    font-size: 11px;
}

.faved-btn {
    background-position: 10px -216px;
}

.md-list li p {
    height: 16px;
    line-height: 16px;
    padding-right: 75px;
    color: #959595;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.md-list li .btn {
    position: absolute;
    top: 13.5px;
    right: 0;
    width: 64px;
    height: 12px;
    line-height: 12px;
    padding: 8px 0;
    text-align: center;
    border-radius: 5px;
    border: 1px solid #00cc7d;
    color: #00cc7d;
}

.md-list li em,
.md-list li span,
.md-list li p {
    display: block;
    margin-left: 65px;
}

.md-list li em {
    display: inline-block;
    margin-left: 10px;
    height: 18px;
    line-height: 18px;
    font-size: 14px;
    padding-right: 75px;
    margin-bottom: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}



em,
i {
    font-style: normal;
    vertical-align: top;
}

.md-list li {
    position: relative;
    margin: 3px 0 15px;
    background: #fff;
    height: 55px;

    margin-bottom: 17px;
}

.list-head {
    padding: 5px 10px;
    margin-bottom: 0;
    background-color: #f5f5f5 !important;
    margin-bottom: 15px;
    height: 19px;
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 15px;

}

.md-list li a:first-child {
    height: 55px;
}

.md-list li a {
    display: block;
    position: relative;
}

.md-list li img {
    float: left;
    width: 55px;
    height: 55px;
    border-radius: 12px;
}

.read-info em {
    float: right;
}

em,
i {
    font-style: normal;
    vertical-align: top;
}

.read-info span {
    padding-left: 19px;
    background: url("https://h.4399.com/images/2022/eyes_icon.png") no-repeat center left;
    background-size: 17px 12px;
}

.read-info {
    color: #959595;
    padding: 0 10px 10px;
}

.collect-detail p {
    margin: 10px;
    word-break: break-all;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    line-height: 20px;
}

.collect-detail img {
    width: 100%;
    display: block;
}

img,
input {
    border: none;
    outline: none;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.collect-detail {
    border-bottom: 5px solid #f3f3f3;
    background-color: #fff;
    margin-top: 48px;
}

.index-btn {
    background: url("https://h.4399.com/images/2022/backindex_icon.png") no-repeat -9px 0;
    background-size: 28px;
    width: 40px;
    height: 38px;
    right: 0;
    background-position: 5px 14px;
    cursor: pointer;
}

.menu_top_list {
    max-width: 500px;
    margin: 0 auto;
    position: fixed;
    height: 48px;
    width: 100%;
    background-color: white;
    color: #333;
    font-size: 16px;
    font-weight: bold;

    z-index: 90;
    top: 0;
}

.menu_top_list li+li {
    width: 64%;
    -webkit-box-pack: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.menu_top_list li {
    float: left;
    display: -webkit-box;
    -webkit-box-align: center;
    height: 48px;
}

.menu_top_list li div {

    height: 48px;
    width: 38px;
    position: absolute;
}


.menu_top_list li:first-child {
    cursor: pointer;
    width: 18%;
    color: #BFBFBF;
    font-size: 20px
}

.menu_top_list li:last-child {
    width: 18%;
    font-size: 12px;
    font-weight: normal;
    color: #959595;
    position: relative;
}

.menu_top_list li:first-child::before {
    background: url("https://rs.sfacg.com/web/m/images/menu_top_icon.png") no-repeat -49.216px 9.96px;
    background-size: 105.462px;
    content: "";
    height: 46.8px;
    width: 24.608px;
    display: block;
}
</style>